package com.test.struts2;
import java.io.File;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class UploadFileAction extends ActionSupport {
    private File upload;
    private String uploadFileName;
    private String uploadContentType;
    private String root;
	public File getUpload() {
		return upload;
	}
	public void setUpload(File upload) {
		this.upload = upload;
	}
	public String getUploadFileName() {
		return uploadFileName;
	}
	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}
	public String getUploadContentType() {
		return uploadContentType;
	}
	public void setUploadContentType(String uploadFileContentType) {
		this.uploadContentType = uploadFileContentType;
	}
	/**
	 * @return
	 */
	public String execute() throws Exception{
		root= ServletActionContext.getServletContext().getRealPath("/"); 
		File f=new File(root);
		f=f.getParentFile();
		System.out.println("root="+root);
		// TODO Auto-generated method stub
		  java.io.InputStream is = new java.io.FileInputStream(upload);
	      java.io.OutputStream os = new java.io.FileOutputStream(f.toString() +"/upload/res_pro/"+ uploadFileName);
	      byte buffer[] = new byte[8192];
	      int count = 0;
	      while((count = is.read(buffer)) > 0) {
	            os.write(buffer, 0, count);
	      }
	      os.close();
	      is.close();
	      return SUCCESS;
	}
}